home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet multimedia / Animacje, filmy i prezentacje / Modelowanie 3D / K-3D 0.6.5.0 / k3d-all-in-one-setup-0.6.5.0.exe / k3d-setup-0.6.5.0.exe / share / shaders / k3d_displace.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-19  |  1.4 KB  |  48 lines

  1. /************************************************************************
  2.  * displace.h - Routines for displacing
  3.  *
  4.  * Author: Larry Gritz (gritzl@acm.org)
  5.  *
  6.  * Reference:
  7.  *   _Advanced RenderMan: Creating CGI for Motion Picture_, 
  8.  *   by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999.
  9.  *
  10.  * $Revision: 1.1 $    $Date: 2004/05/19 18:15:19 $
  11.  *
  12.  ************************************************************************/
  13.  
  14.  
  15.  
  16. #ifndef DISPLACE_H
  17. #define DISPLACE_H 1
  18.  
  19.  
  20.  
  21.  
  22. /* Combine displacement and bump mapping, with units relative to 
  23.  * a particular space.  When truedisp != 0, this function modifies
  24.  * P as a side effect.
  25.  *
  26.  * Inputs:
  27.  *    dir       direction in which to push the surface, assumed to
  28.  *                 already be in "current" space and normalized.
  29.  *    amp       amplitude of the actual displacement or bumping.
  30.  *    space     the name of the coordinate system against which the
  31.  *                 amplitude is measured.
  32.  *    truedisp  when 1, truly displace; when 0, just bump.
  33.  * Return value: the normal of the displaced and bumped surface,
  34.  *                in "current" space, normalized.
  35.  */
  36. normal Displace (vector dir;  string space;
  37.                  float amp; float truedisp;)
  38. {
  39.     extern point P;
  40.     float spacescale = length(vtransform(space, dir));
  41.     vector Ndisp = dir * (amp / max(spacescale,1e-6));
  42.     P += truedisp * Ndisp;
  43.     return normalize (calculatenormal (P + (1-truedisp)*Ndisp));
  44. }
  45.  
  46.  
  47. #endif /* DISPLACE_H */
  48.